home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************/
- /* */
- /* Source - 4th Debugger.c */
- /* Author - Alexander S. Colwell, Copyright © 1990 */
- /* */
- /* Purpose - This application will assist debugging 4th Dimension's */
- /* external area and related external procedures. */
- /* */
- /* Notes - None. */
- /* */
- /************************************************************************/
-
- #define DbgExtArea /* Mark debugging external area */
- #include "4th Debugger.h" /* 4th Dimension Debugger defs */
- #include "4th Class.h" /* 4th Ext Area Class defs */
- #include <StdIO.h> /* Standard I/O defs */
- #include "stdarg.h" /* Standard Variable Args defs */
- #include <string.h> /* String defs */
-
- pascal void C4thMain(); /* Define external procedures */
-
- void main()
- {
- gApplication = new(C4thDbgApp);/* Create new application object */
- gApplication->IApplication(4,4096L,2048L);/* Init application */
- gApplication->Run(); /* Startup application execution */
- gApplication->Exit(); /* Return to da "Finder" */
- }
-
- void C4thDbgApp::IApplication(short extraMasters, Size aRainyDayFund,
- Size aCreditLimit)
- {
- register short i; /* Working index */
-
- eaDoc = NULL; /* Mark no external area window */
- eaIRect.left = eaIRect.top = eaIRect.right = eaIRect.bottom = 0;
-
- for(i = 0; i < 10; i++) /* Init external procedures */
- eaProc[i] = NULL; /* Invalidate external procedure ptr*/
-
- eaName[0] = 0; /* Null external name string */
-
- /* Continue initialization */
- inherited::IApplication(extraMasters,aRainyDayFund,aCreditLimit);
-
- InitExtArea(); /* Init external area */
- }
-
- void C4thDbgApp::InstallExtProc(short epIdx, ProcPtr epPtr)
- {
- short idx = epIdx - ep1; /* Working ext procedure index */
-
- if (idx >= 0 && idx < 10) /* Check if index is valid */
- eaProc[idx] = epPtr; /* Install new procedure pointer */
- }
-
- void C4thDbgApp::SetExtArea(short l, short t, short r, short b)
- {
- eaIRect.left = l; /* Set external rect area */
- eaIRect.top = t;
- eaIRect.right = r;
- eaIRect.bottom = b;
- }
-
- void C4thDbgApp::SetExtName(char *name)
- {
- register long len; /* Working string length */
-
- BlockMove(name,eaName, /* Copy da string */
- len = min((unsigned char)(*name) + 1,sizeof(eaName)));
-
- eaName[0] = len; /* Reset to maximum string length */
- }
-
- void C4thDbgApp::CreateDocument(void)
- {
- register CScrollPane *theScrollPane;/* Working scroll pane object*/
- register CDbgPane *theMainPane;/* Working main pane object */
- Rect margin; /* Working margin rect area */
-
-
- dbgDoc = new(CDbgDoc); /* Create new document object */
-
- dbgDoc->IDocument(this,TRUE);/* Do normal initialization */
-
- dbgDoc->itsWindow = new(CWindow);/* Create new window object */
- dbgDoc->itsWindow->IWindow(dbgWIND,FALSE,gDesktop,dbgDoc);
-
- theScrollPane = new(CScrollPane);/* Create window's scrolling obj*/
- theScrollPane->IScrollPane(dbgDoc->itsWindow,dbgDoc,10,10,0,0,
- sizELASTIC,sizELASTIC,TRUE,TRUE,TRUE);
- theScrollPane->FitToEnclFrame(TRUE,TRUE);
- theMainPane = new(CDbgPane);
- dbgDoc->itsMainPane = theMainPane;
- dbgDoc->itsGopher = theMainPane;
- theMainPane->IEditText(theScrollPane,dbgDoc,
- 1,1,0,0,sizELASTIC,sizELASTIC,432);
- theMainPane->FitToEnclosure(TRUE,TRUE);
- SetRect(&margin,2,2,-2,-2);
- theMainPane->ChangeSize(&margin,FALSE);
- theMainPane->SetFontNumber(monaco);
- theMainPane->SetFontSize(9);
- (*theMainPane->macTE)->crOnly = -1;
- theMainPane->maxChars = maxDbgChars;
-
- theScrollPane->InstallPanorama(theMainPane);
-
- dbgDoc->itsWindow->Select();/* Select our window now!! */
- }
-
- void C4thDbgApp::CreateExtArea(void)
- {
- register CScrollPane *theScrollPane;/* Working scroll pane object*/
- register CEAPane *theMainPane;/* Working main pane object */
- Rect wRect; /* Working rect area */
- EventRecord eaEvent; /* Working event handler */
-
- eaDoc = new(CDocument); /* Create 4th ext area document */
-
- eaDoc->IDocument(this,TRUE);/* Do normal initialization */
-
- eaDoc->itsWindow = new(CWindow);/* Create new window object */
- eaDoc->itsWindow->IWindow(eaWIND,FALSE,gDesktop,eaDoc);
-
- /* Try and fit ext area within window*/
- wRect = eaDoc->itsWindow->macPort->portRect;
- wRect.right = min(max(wRect.right,
- wRect.left + max(0,eaIRect.left) +
- eaIRect.right - eaIRect.left + 32),
- screenBits.bounds.right - screenBits.bounds.left - 16 +
- eaDoc->itsWindow->macPort->portBits.bounds.left);
- wRect.bottom = min(max(wRect.bottom,
- wRect.top + max(0,eaIRect.top) +
- eaIRect.bottom - eaIRect.top + 32),
- screenBits.bounds.bottom - screenBits.bounds.top - 16 +
- eaDoc->itsWindow->macPort->portBits.bounds.top);
- eaDoc->itsWindow->ChangeSize(wRect.right - wRect.left,
- wRect.bottom - wRect.top);
-
- theScrollPane = new(CScrollPane);/* Create window's scrolling obj*/
- theScrollPane->IScrollPane(eaDoc->itsWindow,eaDoc,10,10,0,0,
- sizELASTIC,sizELASTIC,TRUE,TRUE,TRUE);
- theScrollPane->FitToEnclFrame(TRUE,TRUE);
- theScrollPane->SetSteps(16,16);
-
- theMainPane = new(CEAPane); /* Create ext area pane object */
- eaDoc->itsMainPane = theMainPane;
- eaDoc->itsGopher = theMainPane;
-
- wRect = eaIRect; /* Set working external rect area */
-
- /* Init external area's pane */
- theMainPane->IPanorama(theScrollPane,eaDoc,
- wRect.right - wRect.left + abs(wRect.left) + 16,
- wRect.bottom - wRect.top + abs(wRect.top) + 16,
- wRect.left,wRect.top,sizFIXEDSTICKY,sizFIXEDSTICKY);
- theMainPane->FitToEnclosure(TRUE,TRUE);
- theMainPane->SetWantsClicks(TRUE);
- theScrollPane->InstallPanorama(theMainPane);
-
- eaDoc->itsWindow->Select(); /* Select our window now!! */
-
- theMainPane->eaRect = eaIRect;/* Set rect area */
- theMainPane->eaSRect = eaIRect;
- theMainPane->eaObject = NULL;/* Set no external area object */
-
- eaEvent.what = initEvt; /* Initialize event record */
- eaEvent.message = (long)(theMainPane->macPort);
- eaEvent.when = TickCount();
- eaEvent.where.h = eaEvent.where.v = 0;
- eaEvent.modifiers = 0;
-
- theMainPane->DoExtEvent(&eaEvent);/* Do external area event */
- }
-
- void C4thDbgApp::DoCommand(long theCommand)
- {
- switch(theCommand) { /* Process command */
- case cmdAbout: /* About This dialog */
- AboutThis(); break;
-
- case eaOpen: /* Open external area */
- CreateExtArea(); break;
-
- case eaDebugger: /* Hide/Show Debugger */
- dbgDoc->itsWindow->ShowOrHide(!dbgDoc->itsWindow->IsVisible());
- break;
-
- default: /* Don't know this command message */
- inherited::DoCommand(theCommand);/* Cont cmd processing */
- }
- }
-
- void C4thDbgApp::UpdateMenus(void)
- {
- Str255 wStr; /* Working string */
-
- inherited::UpdateMenus(); /* Update other items */
-
- if (!eaDoc) /* Check if external area not opened*/
- gBartender->EnableCmd(eaOpen);/* Enable "Open External Area"*/
- gBartender->EnableCmd(eaDebugger);/* Enable "Hide/Show Debugger"*/
-
- /* Setup "Hide/Show Debugger" item */
- GetIndString(wStr,eaDebugger,(dbgDoc->itsWindow->IsVisible()?1:2));
- gBartender->SetCmdText(eaDebugger,wStr);
- }
-
- void C4thDbgApp::AboutThis(void)
- {
- DialogPtr dPtr; /* Working dialog pointer */
- Point wPt; /* Working mouse point */
-
- /* Display "About This..." dialog */
- if (dPtr = GetNewDialog(atDLOG,(Ptr)(NULL),-1L)) {
- SetPort(dPtr); /* Set to this dialog port */
- DrawDialog(dPtr); /* Draw the items */
- while(TRUE) /* Do until time to quit */
- if (Button()) { /* Check if mouse is down */
- GetMouse(&wPt); /* Get current mouse position */
- if (PtInRect(wPt,&dPtr->portRect))/* Inside window? */
- break; /* Let's break-out now!! */
- }
- DisposDialog(dPtr); /* Kill the dialog!!!! */
- FlushEvents(mDownMask|mUpMask,0);/* Flush all pending events*/
- }
- }
-
- void CEAPane::Dispose(void)
- {
- DoSendEvent(deInitEvt); /* Do external area event */
-
- gApplication->eaDoc = NULL; /* Mark no external area window */
-
- inherited::Dispose(); /* Let's dispose it now */
- }
-
- void CEAPane::UpdateMenus(void)
- {
- inherited::UpdateMenus(); /* Update other items */
-
- gBartender->EnableCmd(eaClose);/* Enable the items */
- gBartender->EnableCmd(ep1);
- gBartender->EnableCmd(ep2);
- gBartender->EnableCmd(ep3);
- gBartender->EnableCmd(ep4);
- gBartender->EnableCmd(ep5);
- gBartender->EnableCmd(ep6);
- gBartender->EnableCmd(ep7);
- gBartender->EnableCmd(ep8);
- gBartender->EnableCmd(ep9);
- gBartender->EnableCmd(cmdUndo);
- gBartender->EnableCmd(cmdCut);
- gBartender->EnableCmd(cmdCopy);
- gBartender->EnableCmd(cmdPaste);
- gBartender->EnableCmd(cmdClear);
- gBartender->EnableCmd(eaSelectAll);
- }
-
- void CEAPane::AdjustToEnclosure(Rect *deltaEncl)
- {
- inherited::AdjustToEnclosure(deltaEncl);/* Do normal stuff */
- FitToEnclosure(TRUE,TRUE); /* Re-adjust to the window */
- }
-
- void CEAPane::AdjustCursor(Point where, RgnHandle mouseRgn)
- {
- EventRecord eaEvent; /* Working event handler */
-
- if (!PtInRect(where,&eaSRect))/* Check if inside ext area? */
- inherited::AdjustCursor(where,mouseRgn);/* Do any other stuff*/
-
- else { /* Nope, it's in ext area */
-
- eaEvent.what = cursorEvt;/* Initialize event record */
- eaEvent.message = (long)(macPort);
- eaEvent.when = TickCount();
- eaEvent.where = where;
- eaEvent.modifiers = DoGetModifiers();
-
- DoExtEvent(&eaEvent); /* Do external area event */
- }
- }
-
- void CEAPane::Dawdle(long *maxSleep)
- {
- inherited::Dawdle(maxSleep);/* Do any other stuff */
-
- DoSendEvent(nullEvent); /* Do external area event */
-
- *maxSleep = 0L; /* Do it as fast as possible */
- }
-
- void CEAPane::Draw(Rect *area)
- {
- Rect wRect; /* Working rect area */
-
- wRect = *area; /* Set to working clipping area */
- FillRect(&wRect,ltGray); /* Draw into unused area */
-
- DoSendEvent(updateEvt); /* Do external area event */
- }
-
- void CEAPane::Scroll(short hDelta, short vDelta, Boolean reDraw)
- {
- OffsetRect(&eaSRect,-hDelta,-vDelta);/* Offset it */
-
- DoSendEvent(scrollEvt); /* Do external area event */
-
- inherited::Scroll(hDelta,vDelta,reDraw);/* OK, let's do it */
- }
-
- void CEAPane::DoClick(Point hitPt, short modifierKeys, long when)
- {
- EventRecord eaEvent; /* Working event handler */
-
- eaEvent.what = mouseDown; /* Initialize event record */
- eaEvent.message = (long)(macPort);
- eaEvent.when = when;
- eaEvent.where = hitPt;
- eaEvent.modifiers = modifierKeys;
-
- DoExtEvent(&eaEvent); /* Do external area event */
- }
-
- void CEAPane::DoKeyDown(char theChar, Byte keyCode, EventRecord *macEvent)
- {
- EventRecord eaEvent; /* Working event handler */
-
- if (eaObject) { /* Check if has C4th object */
- if (eaObject->keyBoardEvents) {/* Check if wants key events */
- eaEvent.what = keyDown;/* Initialize event record */
- eaEvent.message = theChar | (keyCode << 8);
- eaEvent.when = macEvent->when;
- eaEvent.where = lastWhere;
- eaEvent.modifiers = macEvent->modifiers;
-
- DoExtEvent(&eaEvent);/* Do ext area event */
- }
- }
- }
-
- void CEAPane::DoAutoKey(char theChar, Byte keyCode, EventRecord *macEvent)
- {
- DoKeyDown(theChar,keyCode,macEvent);/* Pass it on! */
- }
-
- void CEAPane::Activate(void)
- {
- inherited::Activate(); /* Do other stuff first */
-
- if (eaObject) /* Check if has C4th object */
- if (eaObject->keyBoardEvents)/* Check if want activate evts */
- DoSendEvent(activNote);/* Send message */
- }
-
- void CEAPane::Deactivate(void)
- {
- if (gApplication->eaDoc) /* Check if not quitting */
- if (eaObject) /* Check if has C4th object */
- if (eaObject->keyBoardEvents)/* Want deactivate events */
- DoSendEvent(deActivNote);/* Send message */
-
- inherited::Deactivate(); /* Do other stuff first */
- }
-
- void CEAPane::DoCommand(long theCommand)
- {
- switch(theCommand) { /* Process command */
- case cmdUndo: /* Edit "Undo" event */
- DoSendEvent(undoEvt); break;
-
- case cmdCut: /* Edit "Cut" event */
- DoSendEvent(cutEvt); break;
-
- case cmdCopy: /* Edit "Copy" event */
- DoSendEvent(copyEvt); break;
-
- case cmdPaste: /* Edit "Paste" event */
- DoSendEvent(pasteEvt); break;
-
- case cmdClear: /* Edit "Clear" event */
- DoSendEvent(clearEvt); break;
-
- case eaSelectAll: /* Edit "Select All" event */
- DoSendEvent(selectAllEvt); break;
-
- case eaClose: /* Close External Area */
- inherited::DoCommand(cmdClose); break;
-
- case ep1: /* Execute External Procedure # 1 */
- case ep2: /* Execute External Procedure # 2 */
- case ep3: /* Execute External Procedure # 3 */
- case ep4: /* Execute External Procedure # 4 */
- case ep5: /* Execute External Procedure # 5 */
- case ep6: /* Execute External Procedure # 6 */
- case ep7: /* Execute External Procedure # 7 */
- case ep8: /* Execute External Procedure # 8 */
- case ep9: /* Execute External Procedure # 9 */
- DoExtProc(theCommand - ep1); break;
-
- default: /* None of these, let's inherit */
- inherited::DoCommand(theCommand);/* Cont cmd processing */
- }
- }
-
- void CEAPane::DoSendEvent(short theCommand)
- {
- EventRecord eaEvent; /* Working event handler */
- WindowPtr wPtr = eaObject->wPtr;/* Working window pointer */
-
- if (printing) /* Check if printing */
- GetPort(&wPtr); /* Get current print port */
-
- eaEvent.what = theCommand; /* Initialize event record */
- eaEvent.message = (long)(wPtr);
- eaEvent.when = TickCount();
- eaEvent.where = lastWhere;
- eaEvent.modifiers = DoGetModifiers();
-
- DoExtEvent(&eaEvent); /* Do external area event */
- }
-
- void CEAPane::DoExtEvent(EventRecord *theEvent)
- {
- C4th *wObject; /* Working ext area object */
- Str255 wName; /* Working ext area name */
- Rect wRect; /* Working ext rect area */
-
- Prepare(); /* Prepare for possible drawing */
-
- lastWhere = theEvent->where;/* Save last know "where" point */
-
- wRect = eaRect; /* Set external rect area */
- wObject = eaObject; /* Set external area object handle */
- BlockMove(gApplication->eaName,wName,/* Copy external name */
- (long)(gApplication->eaName[0]));
-
- C4thMain(theEvent,&wRect,wName,&wObject);/* Perform update */
-
- eaObject = wObject; /* Reset external area object handle*/
- }
-
- void CEAPane::DoExtProc(short epIdx)
- {
- C4th *wObject; /* Working 4th object */
-
- if (gApplication->eaProc[epIdx]) {/* Check if it's valid */
- wObject = eaObject; /* Copy ext area object */
- (*gApplication->eaProc[epIdx])(&wObject);/* Pipe it on */
- eaObject = wObject; /* Resave ext area object */
- }
- }
-
- short CEAPane::DoGetModifiers(void)
- {
- KeyMap keyMap; /* Working key map */
- register short modifiers = 0;/* Working modifiers */
-
- GetKeys(&keyMap); /* Get the key map status */
-
- if (keyMap.Key[1] & 0x00000001L)/* Check if got "shift" key */
- modifiers |= shiftKey; /* Set "shift" key modifier */
-
- if (keyMap.Key[1] & 0x00000004L)/* Check if got "option" key */
- modifiers |= optionKey; /* Set "option" key modifier */
-
- if (keyMap.Key[1] & 0x00008000L)/* Check if got "command" key */
- modifiers |= cmdKey; /* Set "command" key modifier */
-
- if (keyMap.Key[1] & 0x00000002L)/* Check if got "caps lock" key */
- modifiers |= alphaLock; /* Set "caps lock" key modifier */
-
- if (!Button()) /* Check if mouse button is up */
- modifiers |= btnState; /* Set button state */
-
- return(modifiers); /* Return key's modifiers */
- }
-
- Boolean CDbgDoc::Close(Boolean quitting)
- {
- register Boolean status = FALSE;/* Closing status indicator */
-
- if (quitting) { /* Check if quitting */
- itsWindow->ShowOrHide(TRUE);/* Let's show it before closing */
- status = inherited::Close(quitting);/* Continue closing */
- }
- else /* Nope, simply hiding da window */
- itsWindow->ShowOrHide(FALSE);/* Let's hide it only */
-
- return(status); /* Return status indicator */
- }
-
- void CDbgPane::DoPrint(fmt,args)
- char *fmt;
- va_list args;
- {
- register short i; /* Working index */
- char buffer[512]; /* Working print output stream buffer*/
- register long bufferLen; /* Working output stream length */
-
- vsprintf(buffer,fmt,&args); /* Copy into output stream buffer */
-
- bufferLen = strlen(buffer); /* Get output stream buffer length */
-
- for(i = 0; i < bufferLen; i++)/* Convert special characters */
- switch(buffer[i]) { /* Process this character */
- case '\t': buffer[i] = ' '; break;
- case '\n': buffer[i] = '\r'; break;
- }
-
- Prepare(); /* Prepare for drawing */
-
- /* Check if text buffer too big */
- if ((*macTE)->teLength + bufferLen > maxChars)
- for(i = 0; (*macTE)->nLines; i++)
- if ((*macTE)->lineStarts[i] > bufferLen) {
- TESetSelect(0L,(long)((*macTE)->lineStarts[i] - 1),macTE);
- TEDelete(macTE);
- }
-
- /* Set it to the end of text buffer */
- TESetSelect((long)((*macTE)->teLength),(long)((*macTE)->teLength),
- macTE);
-
- TEInsert(buffer,bufferLen,macTE);/* Insert text stream */
-
- AdjustBounds(); /* Re-adjust the boundaries */
- ScrollToSelection(); /* Scroll to the cursor location */
- }
-